<template>
  <el-row>
    <el-col :span="5">
      <basic-container>
        <avue-tree :option="treeOption" :data="treeData"
                   @node-click="nodeClick" :loading="treeLoading"
                   :key="key"/>
      </basic-container>
    </el-col>
    <el-col :span="19">
      <basic-container>
        <avue-crud :option="option"
                   :table-loading="loading"
                   :data="data"
                   ref="crud"
                   v-model="form"
                   :page.sync="page"
                   @search-change="searchChange"
                   @search-reset="searchReset"
                   @selection-change="selectionChange"
                   @current-change="currentChange"
                   @size-change="sizeChange"
                   @refresh-change="refreshChange"
                   @on-load="onLoad">
          <template slot="menuLeft">
            <el-dropdown @command="handleCommand">
              <el-button type="primary" size="small" icon="el-icon-arrow-down" v-show="canAdd">
                新 增<!--<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="createNew">新增规则</el-dropdown-item>
                <el-dropdown-item command="createNewFromTemplate">从模板新增规则</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>

            <el-button type="danger"
                       size="small"
                       icon="el-icon-delete"
                       plain
                       @click="handleDelete">删 除
            </el-button>
          </template>
          <template slot-scope="scope" slot="menu">
            <el-button size="small" type="success" plain icon="el-icon-view" circle
                       @click.stop="viewDetail(scope.row)"></el-button>
            <el-button size="small" type="primary" plain icon="el-icon-edit-outline" circle
                       @click.stop="startEdit(scope.row)"></el-button>
            <el-button size="small" type="danger" plain icon="el-icon-delete" circle
                       @click.stop="deleteOne(scope.row)"></el-button>
          </template>
        </avue-crud>
      </basic-container>
    </el-col>
    <div v-if="createNew">
      <el-dialog :title="createTitle"
                 append-to-body
                 :visible.sync="createNew" width="60%" :before-close="createNewClose">
        <avue-form ref="form"
                   v-model="form"
                   :option="firstStep"
                   v-if="createStep==0"
        ></avue-form>
        <avue-form ref="Null"
                   v-model="form"
                   :option="Null"
                   v-if="createStep==1"
                   :key="formKey">
          <template slot="unionNotNull" slot-scope="scope">
            <el-checkbox v-model="form.unionNotNull" true-label='1' false-label='0'
                         @change="changeMultiple"></el-checkbox>
          </template>
        </avue-form>
        <avue-form ref="RANGE"
                   v-model="form"
                   :option="RANGE"
                   v-if="createStep==2"
                   :key="formKey"
        >
          <template slot="checkField" slot-scope="scope">
            <el-select v-model="form.checkField" placeholder="请选择 检查字段" @change="changeRangeType">
              <el-option v-for="item in checkFieldData"
                         :key="item.name"
                         :label="item.name"
                         :value="item.name"></el-option>
            </el-select>
          </template>
          <template slot="valueRange" slot-scope="scope">
            <div v-if="ruleType=='stringType'">
              <el-row>
                <el-col :span="11">
                  <el-input size="small" placeholder="请输入最小值" v-model="form.minValue" :maxlength="maxlength"
                            show-word-limit>
                  </el-input>
                </el-col>
                <el-col :span="2" style="text-align: center;color: #606266">
                  —
                </el-col>
                <el-col :span="11">
                  <el-input size="small" placeholder="请输入最大值" v-model="form.maxValue" :maxlength="maxlength"
                            show-word-limit>
                  </el-input>
                </el-col>
              </el-row>
            </div>
            <div v-if="ruleType=='numberType'">
              <el-row>
                <el-col :span="11">
                  <el-input-number v-model="form.minValue" label="请输入最小值" size="small" style="width: 100%"
                                   :max="form.maxValue"></el-input-number>
                </el-col>
                <el-col :span="2" style="text-align: center;color: #606266">
                  —
                </el-col>
                <el-col :span="11">
                  <el-input-number v-model="form.maxValue" label="请输入最大值" size="small" style="width: 100%"
                                   :min="form.minValue"></el-input-number>
                </el-col>
              </el-row>
            </div>
            <div v-if="ruleType=='TIME'">
              <el-time-picker v-model="form.valueRange" size="small" is-range
                              @change="changeTimeRange"></el-time-picker>
            </div>
            <div v-if="ruleType=='DATE'">
              <el-date-picker v-model="form.valueRange" size="small" type="daterange" @change="changeRange"
                              value-format="yyyy-MM-dd"></el-date-picker>
            </div>
            <div v-if="ruleType=='YEAR'">
              <el-row>
                <el-col :span="11">
                  <el-date-picker placeholder="起始年份" v-model="form.minValue" size="small" type="year"
                                  value-format="yyyy" :picker-options="minValuePickerOptions"></el-date-picker>
                </el-col>
                <el-col :span="2" style="text-align: center;color: #606266">
                  —
                </el-col>
                <el-col :span="11">
                  <el-date-picker placeholder="结束年份" v-model="form.maxValue" type="year" size="small"
                                  value-format="yyyy" :picker-options="maxValuePickerOptions"></el-date-picker>
                </el-col>
              </el-row>
            </div>
            <div v-if="ruleType=='DATETIME'||ruleType=='TIMESTAMP'">
              <el-date-picker v-model="form.valueRange" size="small" type="datetimerange"
                              value-format="yyyy-MM-dd HH:mm:ss" @change="changeRange"></el-date-picker>
            </div>
          </template>
        </avue-form>
        <avue-form ref="LOGIC"
                   v-model="form"
                   :option="LOGIC"
                   v-if="createStep==3"
                   :key="formKey">
          <template slot-scope="{row}" slot="joinTableId">
            <el-select placeholder="请选择 主题表" v-model="row.joinTableId" size="small"
                       @change="chooseTable(row)">
              <el-option
                v-for="item in joinTableDic"
                :key="item.id"
                :label="item.name"
                :value="item.id"></el-option>
            </el-select>
          </template>
          <template slot-scope="{row}" slot="themeJoinFieldName">
            <el-select placeholder="请选择 连接字段（主题表）" v-model="row.themeJoinFieldName" size="small"
                       @focus="changeThemeJoinFieldDic(row)" @change="changeThemeJoinFieldName(row)">
              <el-option
                v-for="item in themeJoinFieldData"
                :key="item.name"
                :label="item.name"
                :value="item.name"></el-option>
            </el-select>
          </template>
          <template slot="checkFormula" slot-scope="scope">
            <el-row>
              <el-col :span="23">
                <el-input size="small" placeholder="请点击编辑按钮编辑检查公式" v-model="form.checkFormula" readonly>
                </el-input>
              </el-col>
              <el-col :span="1">
                <el-button type="primary" icon="el-icon-edit" @click="openEdit(true)"></el-button>
              </el-col>
            </el-row>
          </template>
        </avue-form>
        <avue-form ref="REPEAT"
                   v-model="form"
                   :option="REPEAT"
                   v-if="createStep==4" :key="formKey">
          <template slot="combineRepeat" slot-scope="scope">
            <el-checkbox v-model="form.combineRepeat" true-label='1' false-label='0'
                         @change="changeMultiple"></el-checkbox>
          </template>
        </avue-form>
        <avue-form ref="TIMELY"
                   v-model="form"
                   :option="TIMELY"
                   v-if="createStep==5" :key="formKey">
          <template slot="checkFormula" slot-scope="scope">
            <el-row>
              <el-col :span="23">
                <el-input size="small" placeholder="请点击编辑按钮编辑检查公式" v-model="form.checkFormula" readonly>
                </el-input>
              </el-col>
              <el-col :span="1">
                <el-button type="primary" icon="el-icon-edit" @click="openEdit(false)"></el-button>
              </el-col>
            </el-row>
          </template>
        </avue-form>
        <avue-form ref="STANDARD"
                   v-model="form"
                   :option="STANDARD"
                   v-if="createStep==6" :key="formKey">
          <template slot="specificationType" slot-scope="scope">
            <el-select v-model="form.specificationType" placeholder="请选择 检查字段" @change="changeSpecificationType">
              <el-option v-for="item in specificationTypeDic"
                         :key="item.dictKey"
                         :label="item.dictValue"
                         :value="item.dictKey"></el-option>
            </el-select>
          </template>
          <template slot="lengthRange" slot-scope="scope">
            <el-row>
              <el-col :span="11">
                <el-input-number v-model="form.minLength" label="请输入最小值" size="small" style="width: 100%" :precision="0"
                                 :max="form.maxLength" :min="0"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align: center;color: #606266">
                —
              </el-col>
              <el-col :span="11">
                <el-input-number v-model="form.maxLength" label="请输入最大值" size="small" style="width: 100%" :precision="0"
                                 :min="form.minLength"></el-input-number>
              </el-col>
            </el-row>
          </template>
          <template slot="contain" slot-scope="scope">
            <el-row>
              <el-col :span="14">
                <el-input size="small" placeholder="请输入字符串内容" v-model="form.containString"
                          show-word-limit>
                </el-input>
              </el-col>
              <el-col :span="6">
                <el-select v-model="form.charPosition" placeholder="请选择 字符串位置" @change="delete form.specificPosition">
                  <el-option v-for="item in charPositionDic"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-col>
              <el-col :span="4">
                <div v-if="form.charPosition=='specific'">
                  <el-input-number v-model="form.specificPosition" label="请输入指定位置" size="small" style="width: 100%"
                                   :precision="0" :controls="false"
                                   :min="0"></el-input-number>
                </div>
              </el-col>
            </el-row>
          </template>
          <template slot="regex" slot-scope="scope">
            <el-row>
              <el-col :span="11">
                <el-input size="small" placeholder="请填写正则表达式" v-model="form.regex"
                          show-word-limit>
                </el-input>
              </el-col>
              <el-col :span="11">
                <el-input size="small" placeholder="请填写测试字符串" v-model="testString"
                          show-word-limit>
                </el-input>
              </el-col>
              <el-col :span="2">
                <el-button type="primary" icon="el-icon-circle-check" @click="testRegex"></el-button>
              </el-col>
            </el-row>
          </template>
        </avue-form>
        <avue-form ref="QUOTE"
                   v-model="form"
                   :option="QUOTE"
                   v-if="createStep==7" :key="formKey">
          <template slot="referenceMode" slot-scope="scope">
            <el-select v-model="form.referenceMode" placeholder="请选择 引用方式" @change="changeReferenceMode">
              <el-option label="字典值" value='1'></el-option>
              <el-option label="表字段" value='2'></el-option>
            </el-select>
          </template>
          <template slot="tableField" slot-scope="scope">
            <el-row>
              <el-col :span="8">
                <el-select v-model="form.datasourceId" placeholder="请选择 数据源" @change="changeDatasource">
                  <el-option v-for="item in datasourceDic"
                             :key="item.id"
                             :label="item.name"
                             :value="item.id"></el-option>
                </el-select>
              </el-col>
              <el-col :span="8">
                <el-select v-model="form.tableName" placeholder="请选择 数据表" @change="changeTableName"
                           @focus="checkDatasource">
                  <el-option v-for="item in tableNameDic"
                             :key="item.name"
                             :label="item.name"
                             :value="item.name"></el-option>
                </el-select>
              </el-col>
              <el-col :span="8">
                <el-select v-model="form.fieldName" placeholder="请选择 字段" @focus="checkDatasourceAndTableName">
                  <el-option v-for="item in fieldNameDic"
                             :key="item.name"
                             :label="item.name"
                             :value="item.name"></el-option>
                </el-select>
              </el-col>
            </el-row>
          </template>
        </avue-form>

        <div v-if="editTimeFormula">
          <el-dialog
            width="50%"
            :visible.sync="editTimeFormula"
            :before-close="formulaClose"
            append-to-body>
            <el-row :gutter="10">
              <el-col :span="7">
                <el-tabs type="border-card">
                  <el-tab-pane label="字段列表">
                    <el-tree ref="fieldTree" :data="fieldTreeData" :expand-on-click-node="false" :props="fieldProps"
                             @node-click="fieldTreeClick" style="height: 530px;overflow: auto"></el-tree>
                  </el-tab-pane>
                  <el-tab-pane label="函数">
                    <el-tree ref="functionTree" :data="functionTreeData" :expand-on-click-node="false"
                             :props="functionProps"
                             @node-click="functionTreeClick" style="height: 530px;overflow: auto"></el-tree>
                  </el-tab-pane>
                </el-tabs>
              </el-col>
              <el-col :span="17">
                <el-row>
                  <el-card style="height: 105px">
                    <!--                    <el-button-group>-->
                    <el-button v-for="o in operator" :key="o" type="primary" size="small" plain
                               @click="expression=expression.concat(o)">
                      {{ o }}
                    </el-button>
                    <!--                    </el-button-group>-->
                  </el-card>
                </el-row>
                <el-row style="margin-top: 1%;margin-bottom: 1%">
                  <el-card style="height: 150px">
                    <el-input
                      type="textarea"
                      ref="expression"
                      :autosize="{ minRows: 4, maxRows: 4}"
                      placeholder="请输入表达式内容"
                      v-model="expression">
                    </el-input>
                  </el-card>
                </el-row>
                <el-row>
                  <el-card style="height: 333px;overflow-y: auto">
                    <!--                    //主题表被点击时展示-->
                    <avue-form ref="metaForm"
                               v-model="metaForm"
                               v-if="editTreeType==1"
                               :option="metaOption"></avue-form>

                    <!--                    //函数被点击时展示-->
                    <avue-form ref="functionForm"
                               v-model="functionForm"
                               v-if="editTreeType==2"
                               :option="functionOption">
                      <template slot="args" slot-scope="scope">
                        <avue-crud :option="argsOption"
                                   :data="functionForm.args"
                                   ref="argsCrud">
                        </avue-crud>
                      </template>
                    </avue-form>

                  </el-card>
                </el-row>
              </el-col>
            </el-row>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary"
                         icon="el-icon-receiving"
                         size="small"
                         @click="validateFormula" round
              >验 证
              </el-button>
              <el-button type="primary"
                         icon="el-icon-check"
                         size="small"
                         @click="saveFormula" round
              >保 存
              </el-button>
              <el-button icon="el-icon-document-delete"
                         size="small"
                         @click="formulaClose" round
              >取 消
              </el-button>
            </div>
          </el-dialog>
        </div>

        <div slot="footer" class="dialog-footer">
          <el-button type="primary"
                     icon="el-icon-check"
                     size="small"
                     v-if="createStep==0"
                     @click="newRule"
          >下一步
          </el-button>
          <el-button type="primary"
                     icon="el-icon-check"
                     size="small"
                     v-if="createStep>=1&&!edit"
                     @click="saveRule"
          >保 存
          </el-button>
          <el-button type="primary"
                     icon="el-icon-check"
                     size="small"
                     v-if="createStep>=1&&!edit"
                     @click="saveRuleAndCreateTemplate"
          >保存并生成模板
          </el-button>
          <el-button type="primary"
                     icon="el-icon-check"
                     size="small"
                     v-if="createStep>=1&&edit"
                     @click="submitUpdate"
          >修 改
          </el-button>
          <el-button icon="el-icon-circle-close"
                     size="small"
                     plain
                     @click="createNewClose"
          >取 消
          </el-button>
        </div>
      </el-dialog>
    </div>


    <!--  查看详情  -->
    <div v-if="viewInfo">
      <el-dialog :title="viewInfoTitle"
                 append-to-body
                 :visible.sync="viewInfo" width="60%" :before-close="viewInfoClose">
        <avue-form ref="Null_v"
                   v-model="form"
                   :option="Null_VIEW"
                   v-if="form.type=='Null'"
                   :key="infoKey">
        </avue-form>
        <avue-form ref="RANGE_v"
                   v-model="form"
                   :option="RANGE"
                   v-if="form.type=='RANGE'"
                   :key="infoKey"
        >
          <template slot="valueRange" slot-scope="scope">
            <el-row>
              <el-col :span="11">
                <el-input size="small" placeholder="请输入最小值" v-model="form.minValue"
                          show-word-limit disabled>
                </el-input>
              </el-col>
              <el-col :span="2" style="text-align: center;color: #606266">
                —
              </el-col>
              <el-col :span="11">
                <el-input size="small" placeholder="请输入最大值" v-model="form.maxValue"
                          show-word-limit disabled>
                </el-input>
              </el-col>
            </el-row>
          </template>
        </avue-form>
        <avue-form ref="LOGIC_v"
                   v-model="form"
                   :option="LOGIC_VIEW"
                   v-if="form.type=='LOGIC'"
                   :key="infoKey">
        </avue-form>
        <avue-form ref="REPEAT_v"
                   v-model="form"
                   :option="REPEAT"
                   v-if="form.type=='REPEAT'" :key="infoKey">
        </avue-form>
        <avue-form ref="TIMELY_v"
                   v-model="form"
                   :option="TIMELY"
                   v-if="form.type=='TIMELY'" :key="infoKey">
        </avue-form>
        <avue-form ref="STANDARD_v"
                   v-model="form"
                   :option="STANDARD"
                   v-if="form.type=='STANDARD'" :key="infoKey">
          <template slot="specificationType" slot-scope="scope">
            <el-select v-model="form.specificationType" placeholder="请选择 规范类型">
              <el-option v-for="item in specificationTypeDic"
                         :key="item.dictKey"
                         :label="item.dictValue"
                         :value="item.dictKey"></el-option>
            </el-select>
          </template>
          <template slot="lengthRange" slot-scope="scope">
            <el-row>
              <el-col :span="11">
                <el-input-number v-model="form.minLength" label="请输入最小值" size="small" style="width: 100%" :precision="0"
                                 :max="form.maxLength" :min="0"></el-input-number>
              </el-col>
              <el-col :span="2" style="text-align: center;color: #606266">
                —
              </el-col>
              <el-col :span="11">
                <el-input-number v-model="form.maxLength" label="请输入最大值" size="small" style="width: 100%" :precision="0"
                                 :min="form.minLength"></el-input-number>
              </el-col>
            </el-row>
          </template>
          <template slot="contain" slot-scope="scope">
            <el-row>
              <el-col :span="14">
                <el-input size="small" placeholder="请输入字符串内容" v-model="form.containString"
                          show-word-limit>
                </el-input>
              </el-col>
              <el-col :span="6">
                <el-select v-model="form.charPosition" placeholder="请选择 字符串位置" @change="delete form.specificPosition">
                  <el-option v-for="item in charPositionDic"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-col>
              <el-col :span="4">
                <div v-if="form.charPosition=='specific'">
                  <el-input-number v-model="form.specificPosition" label="请输入指定位置" size="small" style="width: 100%"
                                   :precision="0" :controls="false"
                                   :min="0"></el-input-number>
                </div>
              </el-col>
            </el-row>
          </template>
          <template slot="regex" slot-scope="scope">
            <el-input size="small" placeholder="请填写正则表达式" v-model="form.regex"
                      show-word-limit>
            </el-input>
          </template>
        </avue-form>
        <avue-form ref="QUOTE_v"
                   v-model="form"
                   :option="QUOTE"
                   v-if="form.type=='QUOTE'" :key="infoKey">
          <template slot="referenceMode" slot-scope="scope">
            <el-select v-model="form.referenceMode" placeholder="请选择 引用方式">
              <el-option label="字典值" value='1'></el-option>
              <el-option label="表字段" value='2'></el-option>
            </el-select>
          </template>
          <template slot="tableField" slot-scope="scope">
            <el-input size="small" v-model="form.tableField"></el-input>
          </template>
        </avue-form>
      </el-dialog>
    </div>
  </el-row>
</template>

<script>
import {getModelThemeTree} from "@/api/data_quality/business_model"
import {
  selectPageList,
  generateCode,
  saveRule,
  deleteRules,
  deleteRule,
  updateRule,
  saveRuleAndTemplate
} from "@/api/data_quality/manage_rule"
import {
  getCheckFieldsByThemeId,
  getSpecificCheckFieldsByThemeId,
  getDateTypeCheckFieldsByThemeId
} from "@/api/data_quality/structure_metadata"
import {getOtherThemeTablesByThemeId, getThemeTableTree} from "@/api/data_quality/theme_table"
import {getFunctionTree, validateExpression} from "@/api/data_quality/function"
import {validatenull} from '@/util/validate'
import {dateFormat} from '@/util/date'
import {getDictionary} from '@/api/system/dictbiz'
import {businessModelList} from "@/api/tool/datasource"
import {getTableNames, getTableStructure} from "@/api/data_quality/business_model"
import {getRelationRuleByRuleId} from "@/api/data_quality/relation_rule"
import {getRuleTemplate} from "@/api/data_quality/rule_template"

var stringType = ['CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 'BLOB', 'TEXT', 'ENUM', 'SET', 'VARCHAR2', 'NVARCHAR2', 'NCHAR'];
var numberType = ['INTEGER', 'SMALLINT', 'DECIMAL', 'NUMERIC', 'FLOAT', 'REAL', 'DOUBLE', 'DEC', 'INT', 'TINYINT', 'MEDIUMINT', 'BIGINT', 'NUMBER', 'BINARY_FLOAT', 'BINARY_DOUBLE'];
var dateType = ['DATETIME', 'DATE', 'TIMESTAMP', 'TIME', 'YEAR'];

var operator = {
  expression: "操作符",
  inspectionName: "操作符",
  hasChildren: true,
  children: [
    {
      expression: "'",
      functionMeaning: "引号",
      hasChildren: false,
      inspectionName: "'",
      usageExample: "name='lisa'",
      operator: true,
      args: []
    },
    {
      expression: "(",
      functionMeaning: "左括号",
      hasChildren: false,
      inspectionName: "(",
      usageExample: "name in ('lisa','jeo')",
      operator: true,
      args: []
    },
    {
      expression: ")",
      functionMeaning: "右括号",
      hasChildren: false,
      inspectionName: ")",
      usageExample: "name in ('lisa','jeo')",
      operator: true,
      args: []
    },
    {
      expression: ",",
      functionMeaning: "逗号",
      hasChildren: false,
      inspectionName: ",",
      usageExample: "name in ('lisa','jeo')",
      operator: true,
      args: []
    },
    {
      expression: "+",
      functionMeaning: "加法",
      hasChildren: false,
      inspectionName: "+",
      usageExample: "1+2",
      operator: true,
      args: []
    },
    {
      expression: "-",
      functionMeaning: "减法",
      hasChildren: false,
      inspectionName: "-",
      usageExample: "2-1",
      operator: true,
      args: []
    },
    {
      expression: "*",
      functionMeaning: "乘法",
      hasChildren: false,
      inspectionName: "*",
      usageExample: "1*2",
      operator: true,
      args: []
    },
    {
      expression: "/",
      functionMeaning: "除法",
      hasChildren: false,
      inspectionName: "/",
      usageExample: "1/2",
      operator: true,
      args: []
    },
    {
      expression: "=",
      functionMeaning: "等于",
      hasChildren: false,
      inspectionName: "=",
      usageExample: "name='lisa'",
      operator: true,
      args: []
    },
    {
      expression: "!=",
      functionMeaning: "不等于",
      hasChildren: false,
      inspectionName: "!=",
      usageExample: "name!='lisa'",
      operator: true,
      args: []
    },
    {
      expression: ">",
      functionMeaning: "大于",
      hasChildren: false,
      inspectionName: ">",
      usageExample: "sal>500",
      operator: true,
      args: []
    },
    {
      expression: ">=",
      functionMeaning: "大于等于",
      hasChildren: false,
      inspectionName: ">=",
      usageExample: "sal>=500",
      operator: true,
      args: []
    },
    {
      expression: "<",
      functionMeaning: "小于",
      hasChildren: false,
      inspectionName: "<",
      usageExample: "sal<500",
      operator: true,
      args: []
    },
    {
      expression: "<=",
      functionMeaning: "小于等于",
      hasChildren: false,
      inspectionName: "<=",
      usageExample: "sal<=500",
      operator: true,
      args: []
    },
    {
      expression: "BETWEEN",
      functionMeaning: "在两值之间",
      hasChildren: false,
      inspectionName: "BETWEEN",
      usageExample: "sal BETWEEN 500 AND 800",
      operator: true,
      args: []
    },
    {
      expression: "NOT BETWEEN",
      functionMeaning: "不在两值之间",
      hasChildren: false,
      inspectionName: "NOT BETWEEN",
      usageExample: "sal NOT BETWEEN 500 AND 800",
      operator: true,
      args: []
    },
    {
      expression: "IN",
      functionMeaning: "在集合中",
      hasChildren: false,
      inspectionName: "IN",
      usageExample: "sal IN (500,800,1000)",
      operator: true,
      args: []
    },
    {
      expression: "AND",
      functionMeaning: "与",
      hasChildren: false,
      inspectionName: "AND",
      usageExample: "SAL IN (500,800,1000) AND DEPTNO = 20",
      operator: true,
      args: []
    },
    {
      expression: "OR",
      functionMeaning: "或",
      hasChildren: false,
      inspectionName: "OR",
      usageExample: "SAL IN (500,800,1000) OR DEPTNO = 20",
      operator: true,
      args: []
    },
    {
      expression: "NOT IN",
      functionMeaning: "不在集合中",
      hasChildren: false,
      inspectionName: "NOT IN",
      usageExample: "sal NOT IN (500,800,1000)",
      operator: true,
      args: []
    },
    {
      expression: "LIKE",
      functionMeaning: "模糊匹配",
      hasChildren: false,
      inspectionName: "LIKE",
      usageExample: "job like 'S%'",
      operator: true,
      args: []
    },
    {
      expression: "NOT LIKE",
      functionMeaning: "模糊不匹配",
      hasChildren: false,
      inspectionName: "NOT LIKE",
      usageExample: "job NOT like 'S%'",
      operator: true,
      args: []
    },
    {
      expression: "IS NULL",
      functionMeaning: "为空",
      hasChildren: false,
      inspectionName: "IS NULL",
      usageExample: "job IS NULL",
      operator: true,
      args: []
    },
    {
      expression: "IS NOT NULL",
      functionMeaning: "不为空",
      hasChildren: false,
      inspectionName: "IS NOT NULL",
      usageExample: "job IS NOT NULL",
      operator: true,
      args: []
    },
  ]
}
export default {
  name: "index",
  data() {
    const valueRangeValidate = (rule, value, callback) => {
      if (validatenull(this.form.minValue) || validatenull(this.form.maxValue)) {
        callback(new Error("请填写取值范围！"))
      } else if (this.form.minValue > this.form.maxValue) {
        callback(new Error("最小值必须不大于最大值！"))
      } else {
        callback();
      }
    };
    const lengthRangeValidate = (rule, value, callback) => {
      if (validatenull(this.form.minLength) || validatenull(this.form.maxLength)) {
        callback(new Error("请填写取值范围！"))
      } else if (this.form.minLength > this.form.maxLength) {
        callback(new Error("最小值必须不大于最大值！"))
      } else {
        callback();
      }
    };
    const contentValidate = (rule, value, callback) => {
      if (validatenull(this.form.charPosition)) {
        callback(new Error("请选择所在位置！"))
      } else if (this.form.charPosition == 'specific' && validatenull(this.form.specificPosition)) {
        callback(new Error("请输入指定位置！"))
      } else {
        callback();
      }
    };
    const tableFieldValidate = (rule, value, callback) => {
      if (validatenull(this.form.datasourceId)) {
        callback(new Error("请选择数据源！"))
      } else if (validatenull(this.form.tableName)) {
        callback(new Error("请选择数据源表！"))
      } else if (validatenull(this.form.fieldName)) {
        callback(new Error("请选择字段！"))
      } else {
        callback();
      }
    };
    const that = this;
    return {
      treeLoading: true,
      treeData: [],
      treeOption: {
        addBtn: false,
        menu: false,
        size: 'small',
        props: {
          label: 'title',
          value: 'id',
          children: 'children'
        }
      },
      key: 0,
      formKey: 0,
      form: {
        minValue: null,
        maxValue: null,
        containString: '',
        charPosition: '',
        regex: '',
        referenceMode: '',
        datasourceId: null,
        tableName: '',
        fieldName: '',
        datasourceName: '',
        // enableStatus:1
      },
      data: [],
      selectionList: [],
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: true,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: true,
        column: [
          {
            label: "规则代码",
            prop: "code",
            display: false
          },
          {
            label: "规则类型",
            prop: "type",
            search: true,
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=rule_type",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            span: 24,
            rules: [{
              required: true,
              message: "请选择规则类型",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            search: true,
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            display: false,
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            display: false
          },

        ]
      },
      firstStep: {
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: true,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "规则类型",
            prop: "type",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=rule_type",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            cascaderItem: ['template'],
            span: 24,
            rules: [{
              required: true,
              message: "请选择规则类型",
              trigger: "blur"
            }],
          },
          {
            label: "规则模板",
            prop: "template",
            type: 'select',
            display: false,
            dicUrl: "/api/data-quality/ruleTemplate/listByType?type={{type}}",
            props: {
              label: "code",
              value: "id"
            },
            span: 24,
            rules: [{
              required: true,
              message: "请选择规则模板",
              trigger: "blur"
            }],
          },
        ]
      },
      canAdd: false,
      currentThemeId: '',
      createNew: false,
      createStep: 0,
      createTitle: '',
      checkFieldData: [],
      Null: {
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        detail: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "联合不为空",
            prop: "unionNotNull",
            value: '0',
            formslot: true,
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "检查字段",
            prop: "checkField",
            type: 'select',
            dicData: [],
            multiple: false,
            props: {
              label: "name",
              value: "name"
            },
            dataType: 'string',
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            controlsPosition: 'top',
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      Null_VIEW: {
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        detail: true,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "联合不为空",
            prop: "unionNotNull",
            dicData: [
              {
                label: '是',
                value: '1'
              },
              {
                label: '否',
                value: '0'
              }
            ],
            type: 'radio',
            props: {
              label: 'label',
              value: 'value'
            },
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "检查字段",
            prop: "checkField",
            type: 'select',
            dicData: [],
            multiple: false,
            props: {
              label: "name",
              value: "name"
            },
            dataType: 'string',
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            controlsPosition: 'top',
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      QUOTE: {
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        detail: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "检查字段",
            prop: "checkField",
            type: 'select',
            dicData: [],
            props: {
              label: "name",
              value: "name"
            },
            dataType: 'string',
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "引用方式",
            prop: "referenceMode",
            type: 'select',
            dicData: [
              {
                label: '字典值',
                value: '1'
              },
              {
                label: '表字段',
                value: '2'
              },
            ],
            rules: [{
              required: true,
              message: "请选择引用方式",
              trigger: "blur"
            }],
          },
          {
            label: "字典值",
            prop: "dicBizId",
            type: 'tree',
            props: {
              label: 'title',
              value: 'id'
            },
            display: false,
            dicUrl: '/api/blade-system/dict-biz/tree',
            rules: [{
              required: true,
              message: "请选择字典值",
              trigger: "blur"
            }],
          },
          {
            label: "表字段",
            prop: "tableField",
            formslot: true,
            display: false,
            rules: [
              {
                required: true,
                message: "请选择表字段信息",
                trigger: "blur"
              },
              {
                validator: tableFieldValidate,
                trigger: "blur"
              },],
            value: 'default'
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            controlsPosition: 'top',
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      STANDARD: {
        detail: false,
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "检查字段",
            prop: "checkField",
            type: 'select',
            dicData: [],
            multiple: false,
            props: {
              label: "name",
              value: "name"
            },
            dataType: 'string',
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "规范类型",
            prop: "specificationType",
            formslot: true,
            rules: [{
              required: true,
              message: "请选择规范类型",
              trigger: "blur"
            }],
          },
          {
            label: "规范子类型",
            prop: "specificationSubtype",
            display: false,
            type: 'select',
            dicData: [],
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择规范子类型",
              trigger: "blur"
            }],
          },
          {
            label: "长度范围",
            prop: "lengthRange",
            display: false,
            rules: [{
              validator: lengthRangeValidate,
              trigger: "blur"
            }, {
              required: true,
              message: "请输入长度范围",
              trigger: "blur"
            }],
            value: 'placeholder'
          },
          {
            label: "字符串内容",
            prop: "contain",
            display: false,
            rules: [{
              validator: contentValidate,
              trigger: "blur"
            }, {
              required: true,
              message: "请输入字符串",
              trigger: "blur"
            }],
            value: 'placeholder'
          },
          {
            label: "正则表达式",
            prop: "regex",
            display: false,
            rules: [{
              required: true,
              message: "请输入正则表达式",
              trigger: "blur"
            }],
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            controlsPosition: 'top',
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      TIMELY: {
        detail: false,
        enter: false,
        calcHeight: 30,
        labelWidth: 140,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "检查字段",
            prop: "checkField",
            type: 'select',
            dicData: [],
            props: {
              label: "name",
              value: "name"
            },
            dataType: 'string',
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "允许误差最大天数",
            prop: "maxAllowableErrorDays",
            type: 'number',
            precision: 0,
            minRows: 0,
            value: 0,
            rules: [{
              required: true,
              message: "请输入允许误差最大天数",
              trigger: "blur"
            }],
          },
          {
            label: "检查公式",
            prop: "checkFormula",
            formslot: true,
            span: 24,
            rules: [{
              required: true,
              message: "请输入检查公式",
              trigger: "blur"
            }],
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            controlsPosition: 'top',
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      REPEAT: {
        detail: false,
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "组合重复",
            prop: "combineRepeat",
            formslot: true,
            dicData: [
              {
                label: '是',
                value: '1'
              }
            ],
            type: 'radio',
            props: {
              label: 'label',
              value: 'value'
            },
            value: '0'
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "检查字段",
            prop: "checkField",
            type: 'select',
            dicData: [],
            multiple: false,
            props: {
              label: "name",
              value: "name"
            },
            dataType: 'string',
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            controlsPosition: 'top',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      RANGE: {
        detail: false,
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "检查字段",
            prop: "checkField",
            formslot: true,
            rules: [{
              required: true,
              message: "请选择检查字段",
              trigger: "blur"
            }],
          },
          {
            label: "取值范围",
            prop: "valueRange",
            formslot: true,
            rules: [{
              validator: valueRangeValidate,
              trigger: "blur"
            }, {
              required: true,
              message: "请输入取值范围",
              trigger: "blur"
            },],
            value: 'default'
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            value: 1,
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            controlsPosition: 'top',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      ruleType: '',
      maxlength: null,
      minValuePickerOptions: {
        disabledDate(time) {
          if (validatenull(that.form.maxValue)) {
            return false;
          } else {
            return time.getTime() > new Date(that.form.maxValue + '-12-01 23:59:59')
          }
        },
      },
      maxValuePickerOptions: {
        disabledDate(time) {
          if (validatenull(that.form.minValue)) {
            return false;
          } else {
            return time.getTime() < new Date(that.form.minValue + '-01-01 00:00:00')
          }
        },
      },
      LOGIC: {
        detail: false,
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            span: 24,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "关联关系",
            prop: "relations",
            type: 'dynamic',
            span: 24,
            rules: [{
              required: true,
              message: "请输入关联关系",
              trigger: "blur"
            }],
            children: {
              column: [
                {
                  label: "主题表",
                  prop: "joinTableId",
                  formslot: true,
                  rules: [{
                    required: true,
                    message: "请选择主题表",
                    trigger: "blur"
                  }],
                },
                {
                  label: "连接方式",
                  prop: "joinType",
                  type: 'select',
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=join_type",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  rules: [{
                    required: true,
                    message: "请选择连接方式",
                    trigger: "blur"
                  }],
                },
                {
                  label: "连接字段（主题表）",
                  prop: "themeJoinFieldName",
                  formslot: true,
                  rules: [{
                    required: true,
                    message: "请选择连接字段（主题表）",
                    trigger: "blur"
                  }],
                },
                {
                  label: "连接字段（检查表）",
                  prop: "checkJoinField",
                  type: 'select',
                  dicData: [],
                  props: {
                    label: "name",
                    value: "name"
                  },
                  rules: [{
                    required: true,
                    message: "请选择连接字段（检查表）",
                    trigger: "blur"
                  }],
                },
              ]
            }
          },
          {
            label: "检查公式",
            prop: "checkFormula",
            formslot: true,
            span: 24,
            rules: [{
              required: true,
              message: "请输入检查公式",
              trigger: "blur"
            }],
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            controlsPosition: 'top',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      LOGIC_VIEW: {
        enter: false,
        calcHeight: 30,
        labelWidth: 110,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: false,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        saveBtn: false,
        cancelBtn: false,
        dialogClickModal: false,
        columnBtn: false,
        refreshBtn: false,
        searchShowBtn: false,
        submitBtn: false,
        emptyBtn: false,
        detail: true,
        column: [
          {
            label: "规则代码",
            prop: "code",
            disabled: true,
            span: 24,
            rules: [{
              required: true,
              message: "请输入规则代码",
              trigger: "blur"
            }],
          },
          {
            label: "关联关系",
            prop: "relations",
            type: 'dynamic',
            span: 24,
            rules: [{
              required: true,
              message: "请输入关联关系",
              trigger: "blur"
            }],
            children: {
              column: [
                {
                  label: "主题表",
                  prop: "joinTableName",
                  rules: [{
                    required: true,
                    message: "请选择主题表",
                    trigger: "blur"
                  }],
                },
                {
                  label: "连接方式",
                  prop: "joinType",
                  type: 'select',
                  dicUrl: "/api/blade-system/dict-biz/dictionary?code=join_type",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  rules: [{
                    required: true,
                    message: "请选择连接方式",
                    trigger: "blur"
                  }],
                },
                {
                  label: "连接字段（主题表）",
                  prop: "themeJoinFieldName",
                  rules: [{
                    required: true,
                    message: "请选择连接字段（主题表）",
                    trigger: "blur"
                  }],
                },
                {
                  label: "连接字段（检查表）",
                  prop: "checkJoinField",
                  rules: [{
                    required: true,
                    message: "请选择连接字段（检查表）",
                    trigger: "blur"
                  }],
                },
              ]
            }
          },
          {
            label: "检查公式",
            prop: "checkFormula",
            span: 24,
            rules: [{
              required: true,
              message: "请输入检查公式",
              trigger: "blur"
            }],
          },
          {
            label: "状态",
            prop: "enableStatus",
            type: 'radio',
            value: 1,
            dicData: [
              {
                label: "启用",
                value: 1
              },
              {
                label: "禁用",
                value: 0
              },

            ],
            rules: [{
              required: true,
              message: "请选择状态",
              trigger: "blur"
            }],
          },
          {
            label: "问题级别",
            prop: "problemLevel",
            type: 'select',
            dicUrl: "/api/blade-system/dict-biz/dictionary?code=problem_level",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            rules: [{
              required: true,
              message: "请选择问题级别",
              trigger: "blur"
            }],
            dataType: 'number'
          },
          {
            label: "权重",
            prop: "weight",
            type: 'number',
            controlsPosition: 'top',
            precision: 0,
            minRows: 0,
            maxRows: 10,
            rules: [{
              required: true,
              message: "请输入权重",
              trigger: "blur"
            }],
          },
          {
            label: "描述",
            prop: "describe",
            type: 'textarea',
            span: 24,
            maxlength: 1000,
            minRows: 3,
            showWordLimit: true
          },

        ]
      },
      editTimeFormula: false,
      operator: ['(', ')', ',', '=', '>', '>=', '<', '<=', '!=', 'AND', 'OR'],
      metaForm: {},
      metaOption: {
        calcHeight: 30,
        dialogWidth: 900,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: false,
        selection: false,
        dialogClickModal: false,
        saveBtn: false,
        addBtn: false,
        delBtn: false,
        columnBtn: false,
        refreshBtn: false,
        indexLabel: '序号',
        header: false,
        menuWidth: 150,
        editBtn: false,
        menu: false,
        detail: true,
        labelWidth: 110,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "中文名称",
            prop: "chName",
          },
          {
            label: "英文名称",
            prop: "name",
          },
          {
            label: "字段类型",
            prop: "type",
            width: 100
          },
          {
            label: "字段长度",
            prop: "dataSize",
            width: 80
          },
          {
            label: "小数位",
            prop: "digits",
            width: 80
          },
          {
            label: "是否允许为空",
            prop: "nullable",
            type: 'radio',
            editDisplay: false,
            dicData: [
              {
                label: '是',
                value: 1
              },
              {
                label: '否',
                value: 0
              },
            ],
            width: 100
          },
          {
            label: "默认值",
            prop: "defaultValue",
            width: 80
          },
          {
            label: "是否唯一",
            prop: "ifUnique",
            type: 'radio',
            dicData: [
              {
                label: '是',
                value: 1
              },
              {
                label: '否',
                value: 0
              },
            ],
            width: 80
          },
          {
            label: "字段描述",
            prop: "remark",
          },
        ]
      },
      expression: '',
      fieldTreeData: [],
      fieldProps: {
        label: 'name',
        value: 'id',
        children: 'children'
      },
      functionProps: {
        label: 'expression',
        value: 'inspectionName',
        children: 'children'
      },
      editTreeClickCount: 0,
      editTreeType: 0,
      functionForm: {
        args: []
      },
      functionOption: {
        calcHeight: 30,
        dialogWidth: 900,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: false,
        selection: false,
        dialogClickModal: false,
        saveBtn: false,
        addBtn: false,
        delBtn: false,
        columnBtn: false,
        refreshBtn: false,
        indexLabel: '序号',
        header: false,
        menuWidth: 150,
        editBtn: false,
        menu: false,
        detail: true,
        labelWidth: 80,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "含义",
            prop: "functionMeaning",
            span: 24,
          },
          {
            label: "参数",
            prop: "args",
            formslot: true,
            span: 24,
          },
          {
            label: "示例",
            prop: "usageExample",
            span: 24,
          },
        ]
      },
      argsOption: {
        calcHeight: 20,
        dialogWidth: 900,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: false,
        selection: false,
        dialogClickModal: false,
        saveBtn: false,
        addBtn: false,
        delBtn: false,
        columnBtn: false,
        refreshBtn: false,
        indexLabel: '序号',
        header: false,
        menuWidth: 150,
        editBtn: false,
        menu: false,
        detail: true,
        labelWidth: 80,
        column: [
          {
            label: "参数",
            prop: "parameterName",
            span: 24,
            width: 80
          },
          {
            label: "说明",
            prop: "parameterMeaning",
            span: 24,
          },
        ]
      },
      modelId: '',
      functionTreeData: [],
      joinTableDic: [],
      themeJoinFieldData: [],
      specificationTypeDic: [],
      charPositionDic: [
        {
          label: '任意位置',
          value: 'any'
        },
        {
          label: '开头',
          value: 'prefix'
        },
        {
          label: '结尾',
          value: 'suffix'
        },
        {
          label: '特定位置',
          value: 'specific'
        },
      ],
      testString: '',
      datasourceDic: [],
      tableNameDic: [],
      fieldNameDic: [],
      viewInfo: false,
      info: {},
      infoKey: 0,
      viewInfoTitle: '',
      edit: false,
      fromTemplate: false,
    }
  },
  computed: {
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  mounted() {
    this.getTreeData();
    this.treeLoading = false
  },
  methods: {
    submitUpdate() {
      this.$refs[this.form.type].validate((valid, done) => {
        if (valid) {
          updateRule(this.form).then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.createNewClose();
          })
        }
        done();
      })
    },
    startEdit(row) {
      this.form = row;
      this.currentThemeId = row.themeId;
      switch (this.form.type) {
        case "Null":
          this.createTitle = '空值检查';
          this.createStep += 1;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.Null.column, "checkField");
            checkField.dicData = res.data.data;
          })
          this.changeMultipleEdit(row.unionNotNull);
          break
        case "RANGE":
          this.createTitle = '取值范围检查';
          this.createStep += 2;
          getSpecificCheckFieldsByThemeId(this.currentThemeId).then(res => {
            this.checkFieldData = res.data.data;
            this.checkFieldData.forEach(item => {
              if (item.name == this.form.checkField) {
                if (stringType.indexOf(item.type) > -1) {
                  //字符串类型的
                  this.ruleType = 'stringType';
                } else if (numberType.indexOf(item.type) > -1) {
                  //数组类型的
                  this.ruleType = 'numberType';
                } else if (dateType.indexOf(item.type) > -1) {
                  //日期类型的
                  this.ruleType = item.type;
                  this.form.valueRange = [this.form.minValue, this.form.maxValue]
                }
                this.maxlength = item.dataSize;
              }
            })
          })
          this.ruleType = 'stringType';
          break
        case "LOGIC":
          this.createTitle = '逻辑检查';
          this.createStep += 3;
          getOtherThemeTablesByThemeId(this.currentThemeId).then(res => {
            this.joinTableDic = res.data.data;
          })
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let relations = this.findObject(this.LOGIC.column, "relations");
            let checkJoinField = this.findObject(relations.children.column, "checkJoinField");
            checkJoinField.dicData = res.data.data;
          })
          getRelationRuleByRuleId(row.id).then(res => {
            this.form.relations = res.data.data;
          })
          break
        case "REPEAT":
          this.createTitle = '重复数据检查';
          this.createStep += 4;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.REPEAT.column, "checkField");
            checkField.dicData = res.data.data;
          })
          this.changeMultipleEdit(row.combineRepeat);
          break
        case "TIMELY":
          this.createTitle = '及时性检查';
          this.createStep += 5;
          getDateTypeCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.TIMELY.column, "checkField");
            checkField.dicData = res.data.data;
          })
          break
        case "STANDARD":
          this.createTitle = '规范检查';
          this.createStep += 6;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.STANDARD.column, "checkField");
            checkField.dicData = res.data.data;
          })
          getDictionary({code: 'specification_type'}).then(res => {
            this.specificationTypeDic = res.data.data;
          })
          this.viewSpecificationType(row.specificationType);
          break
        case "QUOTE":
          this.createTitle = '引用完整性检查';
          this.createStep += 7;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.QUOTE.column, "checkField");
            checkField.dicData = res.data.data;
          })
          this.editReferenceMode(row.referenceMode);
          break;

      }
      this.edit = true;
      this.createNew = true;
      this.formKey += 1
    },
    viewInfoClose() {
      this[this.form.type].detail = false;
      this.form = {
        minValue: null,
        maxValue: null,
        containString: '',
        charPosition: '',
        regex: '',
        referenceMode: '',
        datasourceId: null,
        tableName: '',
        fieldName: '',
        // enableStatus:1
      };
      this.viewInfo = false;
      this.infoKey += 1;
      this.viewInfoTitle = '';
    },
    viewDetail(row) {
      this.form = row;
      this.viewInfo = true;
      switch (this.form.type) {
        case "Null":
          this.viewInfoTitle = '空值检查';
          break
        case "RANGE":
          this.viewInfoTitle = '取值范围检查';
          break
        case "LOGIC":
          this.viewInfoTitle = '逻辑检查';
          getRelationRuleByRuleId(row.id).then(res => {
            this.form.relations = res.data.data;
          })
          //获取主题表字典(当前主题表所在模型下的其他表名、表ID)
          break
        case "REPEAT":
          this.viewInfoTitle = '重复数据检查';
          break
        case "TIMELY":
          this.viewInfoTitle = '及时性检查';
          break
        case "STANDARD":
          this.viewInfoTitle = '规范检查';
          getDictionary({code: 'specification_type'}).then(res => {
            this.specificationTypeDic = res.data.data;
          })
          this.viewSpecificationType(row.specificationType);
          break
        case "QUOTE":
          this.viewInfoTitle = '引用完整性检查';
          this.viewReferenceMode(row.referenceMode);
          break
      }
      this[this.form.type].detail = true;
      this.infoKey += 1
    },
    viewSpecificationType(val) {
      let specificationSubtype = this.findObject(this.STANDARD.column, "specificationSubtype");
      let lengthRange = this.findObject(this.STANDARD.column, "lengthRange");
      let contain = this.findObject(this.STANDARD.column, "contain");
      let regex = this.findObject(this.STANDARD.column, "regex");
      specificationSubtype.display = false;
      lengthRange.display = false;
      contain.display = false;
      regex.display = false;
      if (val == '7') {
        specificationSubtype.display = true;
        getDictionary({code: 'specification_type_date'}).then(res => {
          specificationSubtype.dicData = res.data.data;
        })
      } else if (val == '8') {
        specificationSubtype.display = true;
        getDictionary({code: 'specification_type_time'}).then(res => {
          specificationSubtype.dicData = res.data.data;
        })
      } else if (val == '9') {
        specificationSubtype.display = true;
        getDictionary({code: 'specification_type_datetime'}).then(res => {
          specificationSubtype.dicData = res.data.data;
        })
      } else if (val == '15') {
        //选择长度范围出现2个数字框中间用-连接，只能填正整数或者点击增减数量，用来指定对应字段的长度
        lengthRange.display = true;
      } else if (val == '16') {
        //显示文本框用来填写字符串，文本框后为下拉框，下拉框内容为任意位置、开头、结尾、特定位置，选择特定位置时出现位置（数字框）只能填正整数或者点击增减数量
        contain.display = true;
      } else if (val == '17') {
        //出现文本域可以填写正则表达式，测试字符串文本框填写需要测试的字符串，测试按钮可以针对输入的正则表达式对测试字符串进行正则测试
        regex.display = true;
      }
    },
    checkDatasourceAndTableName() {
      if (validatenull(this.form.datasourceId)) {
        this.$message.warning("请先选择数据源！")
      } else if (validatenull(this.form.tableName)) {
        this.$message.warning("请先选择数据表！")
      }
    },
    changeTableName(val) {
      this.form.fieldName = '';
      this.fieldNameDic = [];
      getTableStructure(this.form.datasourceId, val).then(res => {
        this.fieldNameDic = res.data.data;
      })
    },
    checkDatasource() {
      if (validatenull(this.form.datasourceId)) {
        this.$message.warning("请先选择数据源！")
      }
    },
    changeDatasource(val) {
      this.form.tableName = '';
      this.form.fieldName = '';
      this.tableNameDic = [];
      this.fieldNameDic = [];
      getTableNames(val).then(res => {
        this.tableNameDic = res.data.data;
      })
      this.datasourceDic.forEach(item => {
        if (item.id == val) {
          this.form.datasourceName = item.name;
        }
      })
    },
    viewReferenceMode(val) {
      let dicBizId = this.findObject(this.QUOTE.column, "dicBizId");
      let tableField = this.findObject(this.QUOTE.column, "tableField");
      dicBizId.display = false;
      tableField.display = false;
      if (val == '1') {
        dicBizId.display = true;
      } else if (val == '2') {
        this.form.tableField = this.form.datasourceName + '库 ' + this.form.tableName + '表 ' + this.form.fieldName + '字段'
        tableField.display = true;
      }
    },
    editReferenceMode(val) {
      let dicBizId = this.findObject(this.QUOTE.column, "dicBizId");
      let tableField = this.findObject(this.QUOTE.column, "tableField");
      dicBizId.display = false;
      tableField.display = false;
      if (val == 1) {
        dicBizId.display = true;
      } else if (val == 2) {
        businessModelList().then(res => {
          this.datasourceDic = res.data.data;
          tableField.display = true;
        })
      }
    },
    changeReferenceMode(val) {
      this.form.datasourceId = null;
      this.form.tableName = '';
      this.form.fieldName = '';
      this.form.dicBizId = '';
      this.datasourceDic = [];
      this.tableNameDic = [];
      this.fieldNameDic = [];
      let dicBizId = this.findObject(this.QUOTE.column, "dicBizId");
      let tableField = this.findObject(this.QUOTE.column, "tableField");
      dicBizId.display = false;
      tableField.display = false;
      if (val == 1) {
        dicBizId.display = true;
      } else if (val == 2) {
        businessModelList().then(res => {
          this.datasourceDic = res.data.data;
          tableField.display = true;
        })
      }
    },
    testRegex() {
      let regExp = eval(this.form.regex);
      if (regExp.test(this.testString)) {
        this.$message({
          message: '测试字符串可以通过正则表达式的验证！',
          type: 'success'
        });
      } else {
        this.$message({
          message: '测试字符串不能通过正则表达式的验证！',
          type: 'warning'
        });
      }
    },
    changeSpecificationType(val) {
      delete this.form.minLength;
      delete this.form.maxLength;
      delete this.form.specificPosition;
      this.form.specificationSubtype = '';
      this.form.containString = ''
      this.form.charPosition = ''
      this.form.regex = null
      this.testString = ''
      let specificationSubtype = this.findObject(this.STANDARD.column, "specificationSubtype");
      let lengthRange = this.findObject(this.STANDARD.column, "lengthRange");
      let contain = this.findObject(this.STANDARD.column, "contain");
      let regex = this.findObject(this.STANDARD.column, "regex");
      specificationSubtype.display = false;
      lengthRange.display = false;
      contain.display = false;
      regex.display = false;
      if (val == '7') {
        specificationSubtype.display = true;
        getDictionary({code: 'specification_type_date'}).then(res => {
          specificationSubtype.dicData = res.data.data;
        })
      } else if (val == '8') {
        specificationSubtype.display = true;
        getDictionary({code: 'specification_type_time'}).then(res => {
          specificationSubtype.dicData = res.data.data;
        })
      } else if (val == '9') {
        specificationSubtype.display = true;
        getDictionary({code: 'specification_type_datetime'}).then(res => {
          specificationSubtype.dicData = res.data.data;
        })
      } else if (val == '15') {
        //选择长度范围出现2个数字框中间用-连接，只能填正整数或者点击增减数量，用来指定对应字段的长度
        lengthRange.display = true;
      } else if (val == '16') {
        //显示文本框用来填写字符串，文本框后为下拉框，下拉框内容为任意位置、开头、结尾、特定位置，选择特定位置时出现位置（数字框）只能填正整数或者点击增减数量
        contain.display = true;
      } else if (val == '17') {
        //出现文本域可以填写正则表达式，测试字符串文本框填写需要测试的字符串，测试按钮可以针对输入的正则表达式对测试字符串进行正则测试
        regex.display = true;
      }
    },
    changeThemeJoinFieldName(row) {
      this.themeJoinFieldData.forEach(item => {
        if (item.name == row.themeJoinFieldName) {
          row.themeJoinField = item.id;
        }
      })
    },
    changeThemeJoinFieldDic(row) {
      this.themeJoinFieldData = [];
      if (validatenull(row.joinTableId)) {
        this.$message.warning("请先选择主题表！")
      } else {
        getCheckFieldsByThemeId(row.joinTableId).then(res => {
          this.themeJoinFieldData = res.data.data;
        })
      }
    },
    chooseTable(row) {
      row.themeJoinField = '';
      this.themeJoinFieldData = [];
      row.joinTableName = '';
      this.joinTableDic.forEach(item => {
        if (item.id == row.joinTableId) {
          row.joinTableName = item.name
        }
      })
    },
    validateFormula() {
      validateExpression(this.expression).then(res => {
        this.$message({
          type: "success",
          message: res.data.msg
        });
      }, error => {
        window.console.log(error);
      })
    },
    saveFormula() {
      validateExpression(this.expression).then(() => {
        this.form.checkFormula = this.expression;
        this.formulaClose();
      }, error => {
        window.console.log(error);
      })
    },
    formulaClose() {
      this.editTimeFormula = false;
      this.fieldTreeData = [];
      this.functionTreeData = [];
      this.expression = '';
      this.metaForm = {};
      this.functionForm = {};
    },
    functionTreeClick(data) {
      if (data.hasChildren) {
        return;
      }
      this.editTreeClickCount += 1;
      setTimeout(() => {
        if (this.editTreeClickCount == 1) {
          this.functionForm = data;
          this.editTreeType = 2;
        } else if (this.editTreeClickCount > 1 && !data.operator) {
          this.expression = this.expression.concat(data.inspectionName).concat('(')
        } else if (this.editTreeClickCount > 1 && data.operator) {
          this.expression = this.expression.concat(data.inspectionName)
        }
        //归零
        this.editTreeClickCount = 0;
      }, 300)
    },
    fieldTreeClick(data) {
      if (data.hasChildren) {
        return;
      }
      this.editTreeClickCount += 1;
      setTimeout(() => {
        if (this.editTreeClickCount == 1) {
          this.metaForm = data;
          this.editTreeType = 1;
        } else if (this.editTreeClickCount > 1) {
          this.expression = this.expression.concat(data.name)
        }
        //归零
        this.editTreeClickCount = 0;
      }, 300)
    },
    openEdit(other) {
      this.expression = this.form.checkFormula;
      this.editTimeFormula = true;
      let param = this.currentThemeId;
      if (other) {
        //有关联表参数，则组装参数，组装成string
        if (this.form.relations != null && this.form.relations.length > 0) {
          this.form.relations.forEach(item => {
            param = param.concat(',').concat(item.joinTableId)
          })
        }
      }
      getThemeTableTree(param).then(res => {
        this.fieldTreeData = res.data.data;
      })
      getFunctionTree().then(res => {
        res.data.data.push(operator)
        this.functionTreeData = res.data.data;
      })
    },
    changeMultipleEdit(val) {
      let checkField = this.findObject(this[this.form.type].column, 'checkField');
      if (!validatenull(val) && val == '1') {
        checkField.multiple = true;
      } else {
        checkField.multiple = false;
      }
      this.formKey += 1
    },
    changeMultiple(val) {
      let checkField = this.findObject(this[this.form.type].column, 'checkField');
      this.form.checkField = '';
      if (!validatenull(val) && val == '1') {
        checkField.multiple = true;
      } else {
        checkField.multiple = false;
      }
      this.formKey += 1
    },
    saveRuleAndCreateTemplate() {
      this.$refs[this.form.type].validate((valid, done) => {
        if (valid) {
          saveRuleAndTemplate(this.form).then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.createNewClose();
          })
        }
        done();
      })
    },
    saveRule() {
      this.$refs[this.form.type].validate((valid, done) => {
        if (valid) {
          saveRule(this.form).then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.createNewClose();
          })
        }
        done();
      })
    },
    changeTimeRange(val) {
      this.form.minValue = dateFormat(val[0], 'hh:mm:ss');
      this.form.maxValue = dateFormat(val[1], 'hh:mm:ss');
    },
    changeRange(val) {
      this.form.minValue = val[0]
      this.form.maxValue = val[1]
    },
    changeRangeType(val) {
      this.form.minValue = ''
      this.form.maxValue = ''
      this.checkFieldData.forEach(item => {
        if (item.name == val) {
          if (stringType.indexOf(item.type) > -1) {
            //字符串类型的
            this.form.minValue = '';
            this.form.maxValue = '';
            this.ruleType = 'stringType';
          } else if (numberType.indexOf(item.type) > -1) {
            //数组类型的
            this.form.minValue = 0;
            this.form.maxValue = 0;
            this.ruleType = 'numberType';
          } else if (dateType.indexOf(item.type) > -1) {
            //日期类型的
            this.ruleType = item.type;
          }
          this.maxlength = item.dataSize;
        }
      })
    },
    switchType() {
      switch (this.form.type) {
        case "Null":
          this.createTitle = '空值检查';
          this.createStep = 1;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.Null.column, "checkField");
            checkField.dicData = res.data.data;
          })
          this.changeMultipleEdit(this.form.unionNotNull);
          break
        case "RANGE":
          this.createTitle = '取值范围检查';
          this.createStep = 2;
          getSpecificCheckFieldsByThemeId(this.currentThemeId).then(res => {
            this.checkFieldData = res.data.data;
          })
          this.ruleType = 'stringType';
          break
        case "LOGIC":
          this.createTitle = '逻辑检查';
          this.createStep = 3;
          getOtherThemeTablesByThemeId(this.currentThemeId).then(res => {
            this.joinTableDic = res.data.data;
          })
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let relations = this.findObject(this.LOGIC.column, "relations");
            let checkJoinField = this.findObject(relations.children.column, "checkJoinField");
            checkJoinField.dicData = res.data.data;
          })
          //获取主题表字典(当前主题表所在模型下的其他表名、表ID)
          break
        case "REPEAT":
          this.createTitle = '重复数据检查';
          this.createStep = 4;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.REPEAT.column, "checkField");
            checkField.dicData = res.data.data;
          })
          this.changeMultipleEdit(this.form.combineRepeat);
          break
        case "TIMELY":
          this.createTitle = '及时性检查';
          this.createStep = 5;
          getDateTypeCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.TIMELY.column, "checkField");
            checkField.dicData = res.data.data;
          })
          break
        case "STANDARD":
          this.createTitle = '规范检查';
          this.createStep = 6;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.STANDARD.column, "checkField");
            checkField.dicData = res.data.data;
          })
          getDictionary({code: 'specification_type'}).then(res => {
            this.specificationTypeDic = res.data.data;
          })
          if (this.fromTemplate) {
            this.viewSpecificationType(this.form.specificationType);
          } else {
            this.changeSpecificationType(0);
          }
          break
        case "QUOTE":
          this.createTitle = '引用完整性检查';
          this.createStep = 7;
          getCheckFieldsByThemeId(this.currentThemeId).then(res => {
            let checkField = this.findObject(this.QUOTE.column, "checkField");
            checkField.dicData = res.data.data;
          })
          if (this.fromTemplate) {
            this.editReferenceMode(this.form.referenceMode);
          } else {
            this.changeReferenceMode(0);
          }
          break
      }

      generateCode(this.form.type, this.currentThemeId).then(res => {
        this.form.code = res.data.data;
      })
    },
    newRule() {
      this.$refs.form.validate((valid, done) => {
        if (valid) {
          if (this.fromTemplate) {
            //获取模板数据并填充
            getRuleTemplate(this.form.template).then(res => {
              console.log(res)
              delete res.data.data.id;
              delete res.data.data.createUser;
              delete res.data.data.createDept;
              delete res.data.data.createTime;
              delete res.data.data.updateUser;
              delete res.data.data.updateTime;
              delete res.data.data.status;
              delete res.data.data.isDeleted;
              delete res.data.data.code;
              if (res.data.data.themeId != this.form.themeId) {
                res.data.data.checkField = '';
                res.data.data.themeId = this.form.themeId;
              }
              this.form = res.data.data;
              this.switchType();
              this.formKey += 1
              done();
            })
          } else {
            this.switchType();
            this.formKey += 1
            done();
          }


        }
      })
    },
    createNewClose() {
      this.createNew = false;
      this.form = {};
      this.createStep = 0;
      this.maxlength = null;
      this.edit = false;
    },
    handleCommand(command) {
      if (this.currentThemeId != null && this.currentThemeId.length != 0) {
        let template = this.findObject(this.firstStep.column, "template");
        if (command == 'createNew') {
          this.fromTemplate = false;
          template.display = false;
        } else if (command == 'createNewFromTemplate') {
          this.fromTemplate = true;
          template.display = true;
        }
        this.createNew = true;
        this.createTitle = '选择规则类型';
        this.form.themeId = this.currentThemeId;
      }
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return deleteRules(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.$refs.crud.toggleSelection();
        });
    },
    deleteOne(row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return deleteRule(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    getTreeData() {
      getModelThemeTree().then(res => {
        this.treeData = res.data.data;
      })
    },
    nodeClick(data) {
      if (data.hasChildren == true) {
        let themeIds = [];
        data.children.forEach(item => {
          themeIds.push(item.id);
        })
        this.query.themeId = '';
        this.query.themeIds = themeIds.join(",");
        this.currentThemeId = '';
        this.canAdd = false;
        //不可以显示新建按钮
        //并添加当前查询条件
      } else {
        this.query.themeIds = [];
        this.query.themeId = data.id;
        this.currentThemeId = data.id;
        this.canAdd = true;
        this.modelId = data.parentId;
        //可以显示新建按钮
        //并添加查询条件
      }
      //加载右侧表格内容
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      selectPageList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    }
  }
}
</script>

<style scoped>
/deep/ .el-input.is-disabled .el-input__inner {
  background-color: #fff;
  border-color: #DCDFE6;
  color: #606266;
  cursor: not-allowed;
}

/deep/ .el-card.is-always-shadow, .el-card.is-hover-shadow:focus, .el-card.is-hover-shadow:hover {
  border: 1px solid rgb(220, 223, 230);
  background-color: rgb(255, 255, 255);
  color: rgb(48, 49, 51);
  transition: all 0.3s ease 0s;
  box-shadow: rgb(0 0 0 / 12%) 0px 2px 4px 0px, rgb(0 0 0 / 4%) 0px 0px 6px 0px;
}

/deep/ .el-input-number.is-disabled .el-input-number__increase {
  display: none;
}

/deep/ .el-input-number.is-disabled .el-input-number__decrease {
  display: none;
}

/deep/ .avue-crud__empty {
  padding: 10px 0px;
}
</style>
